package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.stat.row.GoodsRows;
import com.cskaoyan.bean.stat.row.OrderRows;
import com.cskaoyan.bean.stat.row.UserRows;
import com.cskaoyan.bean.stat.UserData;
import com.cskaoyan.service.StatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("admin/stat")
public class StatController {

    @Autowired
    StatService statService;

    @RequestMapping("user")
    public BaseRespVo statUser(){

        List<UserRows> rows = statService.statUser();
        UserData userData = new UserData();
        userData.setColumns(new String[] {"day","users"});
        userData.setRows(rows);
        return BaseRespVo.ok(userData);
    }


    @RequestMapping("order")
    public BaseRespVo statOrder(){

        List<OrderRows> rows = statService.statOrder();
        UserData userData = new UserData();
        userData.setColumns(new String[] {"day", "orders", "customers", "amount", "pcr"});
        userData.setRows(rows);
        return BaseRespVo.ok(userData);
    }


    @RequestMapping("goods")
    public BaseRespVo statGoods(){
        List<GoodsRows> rows = statService.statGoods();
        UserData userData = new UserData();
        userData.setColumns(new String[] {"day","orders","products","amount"});
        userData.setRows(rows);
        return BaseRespVo.ok(userData);
    }



}
